package android.Spider;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class PrivateMessageSend extends Activity
{

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);

		m_connection.Initialize(this);
		
		setContentView(R.layout.privatemessagesend);
		m_strTo = getIntent().getStringExtra(ThreadDisplay.s_strUser);
		TextView tv = (TextView)findViewById(R.id.PrivateMessageSendTo);
		if (m_strTo != null && m_strTo.length() > 0)
		{
			tv.setText(m_strTo);
			tv.setFocusable(false);
			((TextView)findViewById(R.id.PrivateMessageSendText)).requestFocus();
		}
	}

	@Override
	protected void onDestroy() {
		m_connection.Unregister();
		super.onDestroy();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    super.onCreateOptionsMenu(menu);
	    
	    menu.add(0, 0, "Send", R.drawable.submitsend);
	    menu.add(0, 1, "Discard", R.drawable.discard);
	    return true;
	}

	@Override
	public boolean onOptionsItemSelected(Menu.Item item)
	{
		if (m_strTo == null || m_strTo.length() == 0)
			m_strTo = ((TextView)findViewById(R.id.PrivateMessageSendTo)).getText().toString();
		
		if (item.getId() == 0)
		{
			m_connection.SendPrivateMessage(m_strTo, ((TextView)findViewById(R.id.PrivateMessageSendText)).getText().toString());
			finish();
			return true;
		}
		else if(item.getId() == 1)
		{
			finish();
			return true;
		}
		
		return false;
	}
	
	String m_strTo;
    XmppConnection m_connection = new XmppConnection() { };

}
